import request from '@/untils/request'
import type {
  postOrderType,
  orderType,
  orderStatus,
  allOrderType,
  statusType,
  CertationTypeResponseData,
  AddOrUpdateUser
} from '@/api/client/type'

enum API {
  // 提交就诊人订单
  POST_ORDER = '/order/orderInfo/auth/submitOrder/',
  // 获取订单
  GET_ORDER = '/order/orderInfo/auth/getOrderInfo/',
  // 取消订单
  GET_CANAL_ORDER = '/order/orderInfo/auth/cancelOrder/',
  // 获取微信支付的二维码
  GET_ERWEIMA = '/order/weixin/createNative/',
  // 查询支付状态
  GET_ORDERSTATUS = '/order/weixin/queryPayStatus/',
  // 获取用户的订单详情
  GET_USERINFO = '/order/orderInfo/auth/',
  // 获取会员
  GET_USER = '/user/auth/getUserInfo',
  // 获取订单状态
  GET_STATUS = '/order/orderInfo/auth/getStatusList',
  //获取证件的类型的接口地址
  CERTIFICATIONTYPE_URL = '/cmn/dict/findByDictCode/',
  // 获取级联信息
  GET_CASCADER = '/cmn/dict/findByParentId/',
  //新增就诊人接口
  ADDUSER_URL = '/user/patient/auth/save',
  //更新已有的就诊人接口
  UPDATEUSER_URL = '/user/patient/auth/update',
  // 删除就诊人
  DELETE_PEO = '/user/patient/auth/remove/'
}

export const postOrder = (hoscode: string, scheduleId: string, patientId: number) =>
  request.post<any, postOrderType>(API.POST_ORDER + `${hoscode}/${scheduleId}/${patientId}`)
export const getOrder = (id: number) => request.get<any, orderType>(API.GET_ORDER + id)

export const getCanalOrder = (orderId: number) =>
  request.get<any, any>(API.GET_CANAL_ORDER + orderId)
export const getEr = (orderId: string) => request.get<any, any>(API.GET_ERWEIMA + orderId)
export const getOrderStatus = (orderId: string) =>
    request.get<any, orderStatus>(API.GET_ORDERSTATUS + orderId)
export const getUserInfo = (page: number, limit: number, patientId: string, orderStatus: string) =>
  request.get<any, allOrderType>(
      API.GET_USERINFO + `${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`
  )
// 获取会员
export const getUser = () => request.get<any, any>(API.GET_USER)
// 获取所有订单状态
export const getStatus = () => request.get<any, statusType>(API.GET_STATUS)
//获取证件类型的方法
export const reqCertationType = (CertificatesType = 'CertificatesType') => request.get<any, CertationTypeResponseData>(API.CERTIFICATIONTYPE_URL + CertificatesType);
// 获取级联信息
export const getCascder = (parentId: string) => request.get<any, any>(API.GET_CASCADER + parentId)

//新增与修改已有的就诊人接口方法
export const reqAddOrUpdateUser = (data: AddOrUpdateUser) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data);
    } else {
        return request.post<any, any>(API.ADDUSER_URL, data);
    }
}
// 删除就诊人信息
export const deletePeoUser = (id: string) => request.delete<any, any>(API.DELETE_PEO + id);